#!/usr/bin/python
# -*- coding: UTF-8 -*-


import time,threading,sys
sys.path.append("/home/biowin/Minibot/04.RobotSamples/03.SpiderRobot")
# sys.path.append("../../")
from BwRobotLib import BwRobotLib
from SpiderRobot import SpiderRobot
from BwSensorLib import BwSensorLib
import os,inspect

# 加载机器人构型配置
fileName = inspect.getframeinfo(inspect.currentframe()).filename
folderPath     = os.path.dirname(os.path.abspath(fileName))
cfile=folderPath+"/config.txt"


class SportRobot:
	def __init__(self):
		# 实例化传感器库对象
		self.sensorlib = BwsensorliblibLib("udp")
		# 实例化BwRobotLib库
		self.robotlib = BwRobotLib("udp")
		# 实例化蜘蛛机器人库
		self.spider = SpiderRobot(self.robotlib)
		# 连接机器人设备
		self.robotlib.connectRobot("10.10.100.254",8899) #真机AP模式
        # 导入机器人配置参数
        self.robotlib.loadConfig(config_file)
		#配置ID
		self.spider.bindIds(self.robotlib.module_ids)
		# 点阵显示
		# 点阵图案：单手俯卧撑　双手俯卧撑　　蹲下　起立 
		self.display_data = [[0x00,0x00,0xFC,0x14,0x22]，[0x00,0x00,0xFF,0x14,0x22],[0x00,0x14,0x08,0x14,0x00],[0x22,0x14,0x08,0x14,0x22]]	
        # RGB彩灯参数
        # [255,255,1] 黄色; [255,1,255] 紫色 [1,255,255] 青色；
        self.rgb_value = [ [255,255,1],[255,1,255],[1,255,255]]
	
	def sportRobotMotion(self):
		#开始检测
		while 1:
			remote= self.sensor.readRemoteSensor()
			print ("返回值：",remote)
			# 按下1
			if(remote==10):
				print("按下＂1＂－－单手俯卧撑")
				self.sensor.setMatrixSensor(self.display_data[0]) # 点阵显示单手俯卧撑图案
				self.sensor.setRGBLightSensor(self.rgb_value[0]) # 亮黄灯
				self.spider.doSport_oneHand() # 蜘蛛机器人做单手俯卧撑
			# 按下2
			if(remote==11):
				print("按下＂2＂－－双手俯卧撑")
				self.sensor.setMatrixSensor(self.display_data[1]) # 点阵显示双手俯卧撑图案
				self.sensor.setRGBLightSensor(self.rgb_value[1]) # 亮紫灯
				self.spider.doSport() # 蜘蛛机器人做双手俯卧撑
			# 按下3
			if(remote==12):
				print("按下＂3＂－－蹲下起立")
				self.sensor.setMatrixSensor(self.display_data[2]) # 点阵显示蹲下图案
				self.mlib.SetDevData(8,0x02,self.RgbValue[2]) # 亮青灯
				self.doUpAndDown() # 蜘蛛机器人蹲下起立
				self.sensor.setMatrixSensor(self.display_data[3]) # 点阵显示起立图案
			
			
# 主函数			
def main():
    # 实例化运动类
    sportRobot = SportRobot()
    # 执行遥控运动功能
    sportRobot.sportRobotMotion()


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print(" Program closed! ")
    pass

